<?php

class apidefinition_errorController extends Zend_Controller_Action
{
  function init() {
  	header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    $this->getHelper('viewRenderer')->setNoRender();
  }

  function createAction() {
    require_once('apidefinition/objects/error.php');
    try{
	  $id = APIDefinition_Object_Error::create($this->_getAllParams());
	  $oError = new APIDefinition_Object_Error($id); 
    } catch(APIDefinition_Object_Exception $e) {
      $data['status'] = 	'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
      return;
    }
    
	$data['status'] = 	'OK';
	$data['error'] = $oError->asArray();
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
    return;
  }
  
  function searchAction() {
    require_once('apidefinition/objects/error.php');
    try {
	    $results = APIDefinition_Object_Error::search($this->_getParam('searchString'));
    } catch(APIDefinition_Object_Exception $e) {
      $data['status'] = 	'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
      return;   		
    }    
    $data['status'] = 	'OK';
    $data['errors'] = $results;
    echo Zend_Registry::get('dt_serializer')->serialize($data);		
  }
  
  function getAction() {
    require_once('apidefinition/objects/error.php');
    try {
      $error = new APIDefinition_Object_Error($this->_getParam('id'));
      $resError = $error->asArray();
    } catch(APIDefinition_Object_Exception $e) {
      $data['status'] = 	'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
      return;
    }
    
    //We list the different controllers of the error
	$data['status'] = 	'OK';
	$data['error'] = $resError;
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
    return;  	
  }

} //End class


?>